<template>
  <a-card :bordered="false">
    <div>
      <a-tabs v-model="activeKey" @change="handleChangeTab">
        <a-tab-pane key='0' tab="生产投料">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
              <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                  <a-col :xl="6" :lg="7" :md="8" :sm="24">
                    <a-form-item label="生产车间">
                      <j-search-select-tag
                        type="list"
                        v-model="queryParamFeeding.workshopCode"
                        :dictOptions="dictOptions"
                        placeholder="请选择所属车间"
                      />
                    </a-form-item>
                  </a-col>
                  <a-col :xl="10" :lg="11" :md="12" :sm="24">
                    <a-form-item label="制单日期">
                      <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParamFeeding.createTime_begin"></j-date>
                      <span class="query-group-split-cust"></span>
                      <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParamFeeding.createTime_end"></j-date>
                    </a-form-item>
                  </a-col>
                  <a-col :xl="6" :lg="7" :md="8" :sm="24">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                      <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
                    </span>
                  </a-col>
                </a-row>
              </a-form>
            </div>
            <!-- 查询区域-END -->
            <!-- 操作按钮区域 -->
            <div class="table-operator">
              <a-button @click="handleAdd" type="primary" icon="plus">添加</a-button>
            </div>
            <!-- table区域-begin -->
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
              <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
              <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
              >项
              <a style="margin-left: 24px" @click="onClearSelected">清空</a>
              <span style="float:right;">
                <a-popover title="自定义列" trigger="click" placement="leftBottom">
                  <template slot="content">
                    <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                      <a-row style="width: 400px">
                        <template v-for="(item,index) in defColumns">
                          <template v-if="item.key!=='rowIndex'&& item.dataIndex!=='action'">
                              <a-col :span="12"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox></a-col>
                          </template>
                        </template>
                      </a-row>
                    </a-checkbox-group>
                  </template>
                  <a><a-icon type="setting" />设置</a >
                </a-popover>
              </span>
            </div>
            <a-table
              ref="feedingTable"
              size="middle"
              bordered
              rowKey="id"
              class="j-table-force-nowrap1"
              :scroll="{x:true}"
              :columns="feedingColumns"
              :dataSource="feedingTable.dataSource"
              :pagination="feedingTable.ipagination"
              :loading="feedingTable.loading"
              :rowSelection="{selectedRowKeys: feedingSelectedRowKeys, onChange: onSelectChangeFeeding, type: 'radio'}"
              :customRow="rowSelectPlan"
              @change="handleTableChange">

              <template slot="htmlSlot" slot-scope="text">
                <div v-html="text"></div>
              </template>
              <template slot="imgSlot" slot-scope="text,record">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
              </template>
              <template slot="fileSlot" slot-scope="text">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                <a-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="downloadFile(text)">
                  下载
                </a-button>
              </template>
            </a-table>
        </a-tab-pane>
        <a-tab-pane key='1' tab="投料记录">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
              <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                  <a-col :xl="6" :lg="7" :md="8" :sm="24">
                    <a-form-item label="包装车间">
                      <j-search-select-tag
                        type="list"
                        v-model="queryParamRecord.workshopCode"
                        :dictOptions="dictOptions"
                        placeholder="请选择所属车间"
                      />
                    </a-form-item>
                  </a-col>
                  <a-col :xl="10" :lg="11" :md="12" :sm="24">
                    <a-form-item label="操作日期">
                      <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParamRecord.createTime_begin"></j-date>
                      <span class="query-group-split-cust"></span>
                      <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParamRecord.createTime_end"></j-date>
                    </a-form-item>
                  </a-col>
                  <a-col :xl="6" :lg="7" :md="8" :sm="24">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                      <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
                    </span>
                  </a-col>
                </a-row>
              </a-form>
            </div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
              <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
              <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
              >项
              <a style="margin-left: 24px" @click="onClearSelected">清空</a>
              <span style="float:right;">
                <a-popover title="自定义列" trigger="click" placement="leftBottom">
                  <template slot="content">
                    <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                      <a-row style="width: 400px">
                        <template v-for="(item,index) in defColumns">
                          <template v-if="item.key!=='rowIndex'&& item.dataIndex!=='action'">
                              <a-col :span="12"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox></a-col>
                          </template>
                        </template>
                      </a-row>
                    </a-checkbox-group>
                  </template>
                  <a><a-icon type="setting" />设置</a >
                </a-popover>
              </span>
            </div>
            <a-table
              ref="recordTable"
              size="middle"
              bordered
              rowKey="id"
              class="j-table-force-nowrap1"
              :scroll="{x:true}"
              :columns="columns"
              :dataSource="recordTable.dataSource"
              :pagination="recordTable.ipagination"
              :loading="recordTable.loading"
              :customRow="rowSelectRecord"
              @change="handleTableChange">

              <template slot="htmlSlot" slot-scope="text">
                <div v-html="text"></div>
              </template>
              <template slot="imgSlot" slot-scope="text,record">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
              </template>
              <template slot="fileSlot" slot-scope="text">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                <a-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="downloadFile(text)">
                  下载
                </a-button>
              </template>

              <span slot="action" slot-scope="text, record">
                <a @click.stop="handleWorkshopPlanDetail(record)">计划明细</a>
                <a-divider type="vertical" />
                <a-dropdown>
                  <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a @click="handleDetail(record)">详情</a>
                    </a-menu-item>
                    <a-menu-item>
                      <a @click="handleWithdraw(record)">撤回</a>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
                <!-- <a @click="handleDetail(record)">详情</a> -->
                <!-- <a-divider type="vertical" /> -->
                <!-- <a @click="handleWithdraw(record)">撤回</a> -->
              </span>
            </a-table>
        </a-tab-pane>
      </a-tabs>
    </div>

    <j-vxe-table keep-source ref="planDetail" v-show="activeKey==='0'" :loading="planDetailTable.loading" :columns="planDetailTable.columns"
          :dataSource="planDetailTable.dataSource" :maxHeight="300" :rowNumber="true" :rowSelection="false"
          :toolbar="false" >
          <template #formulaAction="props">
            <a @click="handleViewPlanFormula(props.row)">配方查看</a>
          </template>
    </j-vxe-table>
    <j-vxe-table keep-source ref="recordDetail" v-show="activeKey==='1'" :loading="recordDetailTable.loading" :columns="recordDetailTable.columns"
          :dataSource="recordDetailTable.dataSource" :maxHeight="300" :rowNumber="true" :rowSelection="false"
          :toolbar="false" />
    <erp-production-feeding-before-modal ref="modalForm" @ok="modalFormOk"/>
    <!-- 配方查看 -->
    <formula-notice-modal ref="formulaNoticeModal" @ok="modalFormOk"/>
    <!-- 计划明细 -->
    <plan-detail-modal ref="planDetailModal" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpProductionFeedingBeforeModal from './modules/ErpProductionFeedingBeforeModal.vue'
  import FormulaNoticeModal from './modules/FormulaNoticeModal.vue'
  import PlanDetailModal from './modules/PlanDetailModal.vue'
  import '@/assets/less/TableExpand.less'
  import { getAction } from '@/api/manage'
  import dayjs from 'dayjs'
  import { JVXETypes } from '@/components/jeecg/JVxeTable'
  import { getDate } from '../../../utils'

  export default {
    name: "ErpProductionFeedingBeforeList",
    mixins:[JeecgListMixin],
    components: {
      ErpProductionFeedingBeforeModal,
      FormulaNoticeModal,
      PlanDetailModal
    },
    data () {
      return {
        description: '生产投料（前配）管理页面',
         // 生产投料（前配）管理页面表头
         feedingColumns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'计划单号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'生产车间',
            align:"center",
            dataIndex: 'workshopCode_dictText'
          },
          {
            title:'执行日期',
            align:"center",
            dataIndex: 'workTime'
          },
          {
            title:'制单人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'制单部门',
            align:"center",
            dataIndex: 'sysOrgCode_dictText'
          },
          {
            title:'制单日期',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?'':(dayjs(text).format('YYYY-MM-DD'))
            }
          },
          {
            title:'是否变更计划',
            align:"center",
            dataIndex: 'isUpdate_dictText'
          },
          {
            title:'生产投料',
            align:"center",
            dataIndex: 'recordTimes'
          },
        ],
        // 投料记录表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'投料记录单号',
            align:"center",
            dataIndex: 'feedingRecordCode'
          },
          {
            title:'单据类型',
            align:"center",
            dataIndex: 'documentType_dictText'
          },
          {
            title:'计划单号',
            align:"center",
            dataIndex: 'planCode'
          },
          {
            title:'配方号',
            align:"center",
            dataIndex: 'formulaNumber'
          },
          {
            title:'生产车间',
            align:"center",
            dataIndex: 'workshopCode_dictText'
          },
          {
            title:'执行日期',
            align:"center",
            dataIndex: 'workTime'
          },
          {
            title:'操作人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'操作部门',
            align:"center",
            dataIndex: 'sysOrgCode_dictText'
          },
          {
            title:'操作时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/feedingbefore/erpProductionFeedingBefore/list",
          delete: "/feedingbefore/erpProductionFeedingBefore/delete",
          deleteBatch: "/feedingbefore/erpProductionFeedingBefore/deleteBatch",
          exportXlsUrl: "/feedingbefore/erpProductionFeedingBefore/exportXls",
          importExcelUrl: "feedingbefore/erpProductionFeedingBefore/importExcel",
          // 撤回
          withdrawRecord: "/feedingbefore/erpProductionFeedingBefore/withdrawRecord",
          //生产投料列表
          // feedingPlanList: "/pro/tslProWorkshopPlan/queryWorkshopPlanList",
          feedingPlanList: "/feedingbefore/erpProductionFeedingBefore/workshopPlanList",
          //计划明细
          // tslProWorkshopPlanDetail: '/pro/tslProWorkshopPlan/queryTslProWorkshopPlanInfoByMainId',
          tslProWorkshopPlanDetail: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/queryDetailListByPlanId',
          //生产投料明细
          recordDetail: "/feedingbefore/erpProductionFeedingBefore/queryErpProductionFeedingBeforeDetailByMainId",
        },
        dictOptions:[],
        superFieldList:[],
        activeKey: '0',
         //查询条件
         queryParamFeeding:{
          createTime_begin:'',
          createTime_end:'',
          workshopCode: null,
        },
        queryParamRecord:{
          createTime_begin:'',
          createTime_end:'',
          workshopCode: null,
        },
        // 选择的生产投料
        feedingSelectionRows: [],
        feedingSelectedRowKeys: [],
        //生产投料列表数据
        feedingTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        //投料记录列表数据
        recordTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        // 生产投料底部明细列表数据
        planDetailTable: {
          loading: false,
          dataSource: [],
          columns: [
          {
            title: '订单编号',
            key: 'orderCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '客户物料编码',
            key: 'customCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '物料编码',
            key: 'productCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '物料名称',
            key: 'productBatchNo',
            type: JVXETypes.normal,
            width: 300,
            defaultValue: '',
          },
          {
            title: '规格型号',
            key: 'materialSpec',
            dataIndex: 'materialSpec',
            type: JVXETypes.normal,
            width: 100,
          },
          {
            title: '配方号',
            key: 'formulaNumber',
            dataIndex: 'formulaNumber',
            width: 100,
            disabled: true,
          },
          {
            title: '生产锅',
            key: 'kettleId',
            dataIndex: 'kettleId',
            width: 180,
            type: JVXETypes.select,
            dictCode: 'tsl_md_kettle,kettle_name,kettle_no',
            disabled: true,
          },
          {
            title: '重量（吨）',
            key: 'planQuantity',
            dataIndex: 'planQuantity',
            width: 120,
          },
          {
            title: '主单位',
            key: 'meUnit',
            dataIndex: 'meUnit',
            dictCode: 'ji_unit',
            type: JVXETypes.select,
            width: 100,
            disabled: true,
          },
          {
            title: '计划数量',
            key: 'planQuantity',
            dataIndex: 'planQuantity',
            width: 120,
          },
          {
            title: '完成数量',
            key: 'completedQuantity',
            dataIndex: 'completedQuantity',
            width: 120,
          },
          {
            title: '剩余数量',
            key: 'residualQuantity',
            dataIndex: 'residualQuantity',
            width: 120,
          },
          {
            title: '包装车间',
            key: 'packshopCode',
            type: JVXETypes.select,
            dictCode: 'sys_depart,depart_name,org_code,workshop_type=3 or workshop_type=4',
            width: 120,
            disabled: true,
          },
          {
              title: '操作',
              key: 'action',
              width: 100, // 固定宽度
              fixed: 'right', // 固定在左侧
              type: JVXETypes.slot, // 使用插槽方式
              slotName: 'formulaAction' // 自定义插槽名称
            },
          ],
        },
        // 投料记录底部明细列表数据
        recordDetailTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '物料编码',
              key: 'materialCode',
              type: JVXETypes.normal,
              minWidth: 180,
              disabled: true,
            },
            {
              title: '编码名称',
              key: 'materialName',
              type: JVXETypes.normal,
              minWidth: 300,
              disabled: true,
            },
            {
              title: '规格型号',
              key: 'materialSpec',
              type: JVXETypes.normal,
              minWidth: 120,
              disabled: true,
            },
            {
              title: '单位',
              key: 'meUnit',
              dictCode: 'ji_unit',
              type: JVXETypes.select,
              minWidth: 100,
              disabled: true,
            },
            {
              title: '批次号',
              key: 'batchNo',
              minWidth: 100,
              type: JVXETypes.normal,
              disabled: true,
            },
            {
              title: '物料批号',
              key: 'materialBatchNo',
              minWidth: 180,
              type: JVXETypes.normal,
              disabled: true,
            },
            {
              title: '投料数量',
              key: 'feedingNum',
              type: JVXETypes.normal,
              minWidth: 100,
              disabled: true,
            },
          ],
        },
        settingColumns: [],
      }
    },
    watch: {
      // 对车间选择的监听
      'queryParamFeeding.workshopCode': {
        handler(newVal, oldVal) {
          // 当车间变化时自动触发查询
          if (newVal !== oldVal) {
            this.handleWorkshopChange();
          }
        },
        immediate: false
      },
      'queryParamRecord.workshopCode': {
        handler(newVal, oldVal) {
          // 当车间变化时自动触发查询
          if (newVal !== oldVal) {
            this.handleWorkshopChange();
          }
        },
        immediate: false
      },
    },
    created() {
      this.queryParamFeeding.createTime_begin = getDate('day', -7)
      this.queryParamFeeding.createTime_end = getDate('day', 0)
      this.queryParamRecord.createTime_begin = getDate('day', -7)
      this.queryParamRecord.createTime_end = getDate('day', 0)
      this.getSuperFieldList();
      // 获取车间字典，默认选择第一个
      this.loadworkshopDict();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      // 加载车间字典 --> 默认选择第一条下拉数据
      loadworkshopDict(){
        getAction(`/sys/dict/getDictItems/erp_production_execution_organization,depart_name,depart_code`,{}).then(res=>{
          if(res.success){
            this.dictOptions = res.result.map(item => ({value: item.value, text: item.text}))
            if(this.dictOptions.length > 0 || this.dictOptions.length > 0){
              this.queryParamFeeding.workshopCode = this.dictOptions[0].value
              this.queryParamRecord.workshopCode = this.dictOptions[0].value
            }
          } else {
            console.error('getDictItems error: : ', res)
            this.dictOptions = []
          }
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
         fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
         fieldList.push({type:'date',value:'createTime',text:'创建日期'})
         fieldList.push({type:'string',value:'sysOrgCode',text:'所属部门',dictCode:''})
         fieldList.push({type:'string',value:'feedingRecordCode',text:'投料记录单号',dictCode:''})
         fieldList.push({type:'string',value:'formulaNumber',text:'配方号',dictCode:''})
         fieldList.push({type:'string',value:'workshopCode',text:'生产车间',dictCode:''})
        this.superFieldList = fieldList
      },
      // 修改查询方法
      searchQuery() {
         // 重置为第一页
        if (this.activeKey === '0') {
          this.feedingTable.ipagination.current = 1;
        } else {
          this.recordTable.ipagination.current = 1;
        }
        // 调用查询
        this.loadFeedingRecordData()
      },
      handleChangeTab() {
        // 将底部明细列表置空
        this.planDetailTable.dataSource = [];
        this.recordDetailTable.dataSource = [];
        this.loadFeedingRecordData()
      },
      // 修改：添加分页处理方法
      handleTableChange(pagination, filters, sorter, { currentDataSource }) {
        // 根据当前激活的标签页更新对应的分页参数
        if (this.activeKey === '0') {
          this.feedingTable.ipagination = {
            ...this.feedingTable.ipagination,
            current: pagination.current,
            pageSize: pagination.pageSize
          };
        } else {
          this.recordTable.ipagination = {
            ...this.recordTable.ipagination,
            current: pagination.current,
            pageSize: pagination.pageSize
          };
        }
        // 重新加载数据
        this.loadFeedingRecordData();
      },
      // 添加
      handleAdd: function () {
        if (this.queryParamFeeding.workshopCode === '' || this.queryParamFeeding.workshopCode === null) {
            this.$message.warning('请选择车间')
            return
        }
        if (this.feedingSelectionRows.length <= 0) {
            this.$message.warning('请选择生产投料')
            return
        }
        const feedingData = {
          planId: this.feedingSelectionRows[0].id,
          planCode: this.feedingSelectionRows[0].code,
          workTime: this.feedingSelectionRows[0].workTime,
          workshopCode: this.queryParamFeeding.workshopCode,
        }
        // 点击添加时，获取当前查询框的车间值并传递给form
        this.$refs.modalForm.getWorkshopCode(feedingData);
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '添加'
        this.$refs.modalForm.disableSubmit = false
      },
      // 修改modalFormOk方法
      modalFormOk() {
        // 将底部明细列表置空
        this.planDetailTable.dataSource = [];
        // 添加成功后刷新列表
        this.loadFeedingRecordData();
      },
      // 撤回
      handleWithdraw: function (record) {
        let that = this;
        that.$confirm({
          title: "投料撤回",
          content: "是否撤回选中数据?",
          onOk: function() {
            that.withdrawRecord(record.id+'')
            that.onClearSelected();
          }
        });
      },
      async withdrawRecord(id) {
        try {
          const res = await getAction(this.url.withdrawRecord, {id})
          if (res.success) {
            this.$message.success(res.result)
            this.loadFeedingRecordData();
            // 将底部明细列表置空
            this.recordDetailTable.dataSource = [];
            return res.result
          } else {
            this.$message.warning(res.message)
            return ''
          }
        } catch (e) {
          console.error("撤回失败", e)
          return ''
        }
      },
      //this.activeKey：0为生产投料，1为投料记录。
      loadFeedingRecordData() {
        let urlList = this.url.feedingPlanList
        let tableRef = this.activeKey === '0' 
          ? 'feedingTable' 
          : 'recordTable';
        // 设置加载状态
        this[tableRef].loading = true;
        urlList = this.activeKey === '0' 
            ? this.url.feedingPlanList 
            : this.url.list;
        // 获取当前表格的分页参数
        const pagination = this.activeKey === '0' 
          ? this.feedingTable.ipagination 
          : this.recordTable.ipagination;
        // 设置查询参数
        const queryParam = this.activeKey === '0' 
          ? this.queryParamFeeding 
          : this.queryParamRecord;
        const params = {
          ...queryParam,
          pageNo: pagination.current,
          pageSize: pagination.pageSize
        };
        getAction(urlList, params)
          .then((res) => {
            if (res.success) {
              this[tableRef].dataSource = res.result.records || res.result || [];
              if (res.result.total) {
                this[tableRef].ipagination.total = res.result.total;
              } else {
                this[tableRef].ipagination.total = 0;
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this[tableRef].loading = false;
          })
          this.feedingSelectedRowKeys = [];
          this.feedingSelectionRows = [];
      },
      // 生产投料 选中时将所选数据的id赋给feedingSelectedRowKeys
      onSelectChangeFeeding(selectedRowKeys, selectionRows) {
        this.feedingSelectedRowKeys = selectedRowKeys
        this.feedingSelectionRows = selectionRows;
        let params = {
          id: selectedRowKeys[0]
        }
        this.loadPlanDetailData(params)
      },
      // 车间变化处理方法
      handleWorkshopChange() {
         // 将所选数据置空
         this.feedingSelectedRowKeys = [];
         this.feedingSelectionRows = [];
         // 将底部明细列表置空
         this.planDetailTable.dataSource = [];
         this.recordDetailTable.dataSource = [];
          // 重置当前标签页的分页到第一页
          if (this.activeKey === '0') {
            this.feedingTable.ipagination.current = 1;
          } else {
            this.recordTable.ipagination.current = 1;
          }
          // 触发数据加载
          this.loadFeedingRecordData();
      },
      rowSelectPlan(record, index) {
        return {
          on: {
            click: (event) => {
              let params = { id: record.id }
              this.loadPlanDetailData(params)
            },
          },
        }
      },
      rowSelectRecord(record, index) {
        return {
          on: {
            click: (event) => {
              let params = { 
                // feedingRecordId: record.id,
                // planId: record.planId,
                id: record.id,
              }
              this.loadRecordDetailData(params)
            },
          },
        }
      },
      // 获取生产计划明细
      loadPlanDetailData(params) {
        this.planDetailTable.dataSource = []
        if(params.id){
          this.planDetailTable.loading = true
          getAction(this.url.tslProWorkshopPlanDetail, params)
          .then((res) => {
            if (res.success) {
              this.planDetailTable.dataSource = res.result
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.planDetailTable.loading = false;
          })
        }
      },
      // 获取生产投料明细
      loadRecordDetailData(params) {
        this.recordDetailTable.dataSource = []
        if(params.id){
          this.recordDetailTable.loading = true
          getAction(this.url.recordDetail, params)
          .then((res) => {
            if (res.success) {
              this.recordDetailTable.dataSource = res.result
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.recordDetailTable.loading = false;
          })
        }
      },
      // 配方查看
      handleViewPlanFormula(row) {
        this.$refs.formulaNoticeModal.edit(row);
        this.$refs.formulaNoticeModal.title = "配方查看";
      },
      // 计划明细
      handleWorkshopPlanDetail(row) {
        this.$refs.planDetailModal.detail(row);
        this.$refs.planDetailModal.title = "计划明细";
        this.$refs.planDetailModal.disableSubmit = false
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>